const mysql = require('../db/mysql57');

const storageDao = {
    setItem(uid, key, value) {
        let sql = `insert into WebStorage(uid, k, value) values(?, ?, ?)`;
        let data = [ uid, key, value ];
        return mysql.sqlExec(sql, data);
    },
    getItem(uid, key) {
        let sql = `select value from WebStorage where uid = ? and k = ? and isDel = ? order by id desc limit 1`;
        let data = [ uid, key, 'false' ];
        return mysql.sqlExec(sql, data);
    },
    removeItem(uid, key) {
        let sql = `update WebStorage set isDel = ? where uid = ? and k = ?`;
        let data = [ 'true', uid, key ];
        return mysql.sqlExec(sql, data);
    },
};

module.exports = storageDao;